from PySide2.QtCore import Qt, QObject
from PySide2.QtCore import Signal, Slot
from PySide2.QtCore import QTimer
from PySide2.QtGui import QImage, QMatrix, QPixmap
from PySide2.QtWidgets import QWidget, QLabel, QHBoxLayout

class WWaitingSignals(QObject):
    timeout = Signal()

class WWaiting(QWidget):
    signals = WWaitingSignals()
    def __init__(self, parent=None):
        super(WWaiting, self).__init__(parent)

        self._ui_main_layout = QHBoxLayout()
        
        self._ui_img_lbl = QLabel()
        # self._ui_img_lbl.setMinimumSize(32, 32)
        self._ui_img = QImage("3rdparty\RemixIcon\System\loader-4-fill.svg")
        # self._ui_img.scaled(12, 12)

        self._ui_lbl_count = QLabel()

        self._ui_main_layout.addWidget(self._ui_img_lbl)
        self._ui_main_layout.addWidget(self._ui_lbl_count)
        self._ui_main_layout.addStretch(0)
        self._ui_main_layout.addSpacing(0)

        self.setLayout(self._ui_main_layout)

        self._count = 0

        self.t = QTimer(self)
        self.t.timeout.connect(self._update)

        self.hide()

    def start(self, tmo):
        self._timeout = tmo
        self._count = 0
        self.t.start(100)
        self.show()

    def stop(self):
        self.t.stop()
        self.hide()

    def _update(self):
        if self._count < self._timeout*10:
            self._count += 1
        else:
            self.t.stop()
            self.hide()
            self.signals.timeout.emit()
        _ui_matrix = QMatrix()
        _ui_matrix.scale(0.8, 0.8)
        _ui_matrix.rotate(self._count*90)
        trans_image = self._ui_img.transformed(_ui_matrix, Qt.SmoothTransformation)
        self._ui_img_lbl.setPixmap(QPixmap.fromImage(trans_image))    

        self._ui_lbl_count.setText(str(self._count/10))        


if __name__=="__main__":
    import sys
    from PySide2.QtWidgets import QApplication
    a = QApplication()
    w = WWaiting()
    w.start(1000)
    w.show()
    sys.exit(a.exec_())